<?php

class DB_COMMENT extends ORM_Table {
    
    static protected $table_name = 'comment';
    
    static public function getTableName($params = null) {
        return self::$table_name;
    }
    
    static function store($comments_arr){
        
        if(!is_array($comments_arr)){
            return null;
        }
        
        $re = array();
        foreach ($comments_arr as $k1 => $comments) {
             $rs = ORM_Finder::findOne('DB_COMMENT', array('mid'=>$comments['mid']));

            //更新用户信息
            DB_WEIBO::batch_save(array($comments['status']['user']));

            if(!$rs){
                $rs = new DB_COMMENT();
                $rs->setWeiboId($comments['status']['user']['idstr']);
                $rs->setFromId($comments['user']['idstr']);
                $rs->setText($comments['text']);
                $rs->setSource($comments['source']);
                $rs->setIdstr($comments['idstr']);
                $rs->setMid($comments['mid']);
                $rs->setCreatedAt(date('Y-m-d H:i:s',  strtotime($comments['created_at'])));
                $rs->setUser(serialize($comments['status']['user']));
                $rs->save();
            }
            $re[$rs->getId()]   = $rs->toArray();
        }
        
        return $re;
    }
}

?>
